package p.ithorns.integration.hazelcast;

import com.hazelcast.console.Echo;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IExecutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import p.ithorns.integration.hazelcast.execute.SumTask;

import java.util.concurrent.Future;

/**
 * HazelcastApp
 *
 * @author Ht.L
 * @date 2023-10-01 19:57
 * @since 1.0.0
 */
//@EnableScheduling
@SpringBootApplication(scanBasePackages = "p.ithorns.integration")
public class HazelcastApp implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(HazelcastApp.class, args);
    }

    @Autowired
    HazelcastInstance hz;

    @Override
    public void run(String... args) throws Exception {
//        Endpoint localEndpoint = hz.getLocalEndpoint();
//        System.out.println("=========>" + localEndpoint);
//        IMap<Object, Object> temp = hazelcastInstance.getMap("temp");
//        temp.put("K1", "V1");

        IExecutorService executorService = hz.getExecutorService( "executorService" );
        Future<String> future = executorService.submit( new Echo( "myinput") );
        //while it is executing, do some useful stuff
        //when ready, get the result of your execution
        String result = future.get();
        System.out.println("===============> " + result);

        executorService.submit(new SumTask());

    }



}